using AppToolKit.Model;
using AppToolKit.Model.Validation;
using System;
namespace AppToolKit.Business.MasterDetail
{
	public class MasterDetailBusinessBase<TMaster, TDetail> : BusinessBase<TMaster>, IMasterDetailBusiness<TMaster, TDetail> where TMaster : class, IMasterEntity where TDetail : class, IDetailEntity
	{
		private IDetailBusiness<TDetail> detailBusines_;
		public IDetailBusiness<TDetail> DetailBusiness
		{
			get
			{
				return this.detailBusines_;
			}
			set
			{
				this.detailBusines_ = value;
			}
		}
		protected override void ValidateChain(TMaster entity, ValidateBehavior behavior)
		{
			base.ValidateChain(entity, behavior);
			if (this.detailBusines_ != null)
			{
				foreach (TDetail data in entity.Items)
				{
					ValidateResultSet validateResultSet = this.detailBusines_.Valid(data, behavior);
					if (!validateResultSet.IsValid)
					{
						throw new ValidateException
						{
							ResultSet = validateResultSet
						};
					}
				}
			}
		}
	}
}
